package com.kittenhuffing;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.World;
import org.newdawn.slick.*;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;


public class GameplayState extends BasicGameState {
	private int state = -1;
	private boolean quitting = false;
	private World physics;
	private Environment env;
	
	GameplayState(int state) {
		this.state = state;
	}
	
	public World getPhysics() {
		return physics;
	}

	@Override
	public void init(GameContainer gc, StateBasedGame game)
			throws SlickException {
		//Create world
		Vec2 gravity = new Vec2(0, KittenHuffing.GRAVITY);
		physics = new World(gravity, true);
		
		env = new Environment(this);
		
	}
	
	@Override
	public void keyPressed(int key, char c) {
		if((int) c==27) {
			quitting = true;
		}
	}

	@Override
	public void render(GameContainer gc, StateBasedGame game, Graphics graphics)
			throws SlickException {
		env.render(gc);
		physics.step(1/60, 10, 10);
		if(quitting) {
			gc.exit();
		}
		
	}

	@Override
	public void update(GameContainer gc, StateBasedGame game, int arg2)
			throws SlickException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public int getID() {
		return state;
	}

}
